﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using UFC.Common;
using System.Configuration;
namespace SendToWCAPPDispatchInfo
{
    public partial class Send_DispatchInfo : ServiceBase
    {
        private System.Timers.Timer m_SyncTimer;
        private System.Timers.Timer m_SyncTimer2;
        public Send_DispatchInfo()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            LogHelp.SetConfig();
            m_SyncTimer = new System.Timers.Timer();
            m_SyncTimer.Enabled = false;
            m_SyncTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_SyncTimer_Elapsed);

            m_SyncTimer.Interval =  1000;
            m_SyncTimer.Enabled = true;
            m_SyncTimer.Start();

            //定时器2
           //m_SyncTimer2 = new System.Timers.Timer();
           // m_SyncTimer2.Enabled = false;
           // m_SyncTimer2.Elapsed += new System.Timers.ElapsedEventHandler(m_SyncTimer_Elapsed2);
           // int intSync = Convert.ToInt32(ConfigurationManager.AppSettings["sync"].ToString());
           // m_SyncTimer2.Interval = intSync  * 1000;//*1440
           // m_SyncTimer2.Enabled = true;
           // m_SyncTimer2.Start();
        }

        private void m_SyncTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                LogHelp.WriteLog("派工信息结转启动");
                m_SyncTimer.Enabled = false;
                SendDispatchInfo runMain = new SendDispatchInfo();
                runMain.RunDispatchTableSync();
            }
            catch (Exception myError)
            {
                LogHelp.WriteError(myError.Message, myError);
            }
            finally
            {
                m_SyncTimer.Enabled = true;
            }
        }

        private void m_SyncTimer_Elapsed2(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                LogHelp.WriteLog("派工推送服务启动");
                m_SyncTimer.Enabled = false;
                SendDispatchInfo runMain = new SendDispatchInfo();
                runMain.RunSendDispatchSync();
            }
            catch (Exception myError)
            {
                LogHelp.WriteError(myError.Message, myError);
            }
            finally
            {
                m_SyncTimer.Enabled = true;
            }
        }
        protected override void OnStop()
        {
        }
    }
}
